package cn.com.crc.ems.rest.service.impl;

import cn.com.crc.ems.rest.dto.FormStructure;
import cn.com.crc.ems.rest.dto.QueryDto;
import cn.com.crc.ems.rest.lucene.LuceneUtil2;
import cn.com.crc.ems.rest.service.LuceneService;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class LuceneServiceImpl implements LuceneService {


    @Autowired
    private LuceneUtil2 luceneUtil;


    @Override
    public List<FormStructure> searchData(QueryDto query) {
        log.info("lucene查询:" + JSONObject.toJSONString(query));
        List<FormStructure> formStructureList = luceneUtil.queryIndex(query);
        return formStructureList;
    }

    @Override
    public void delData(String formId) {
        luceneUtil.deleteIndex(formId);
    }

    @Override
    public void updateData(FormStructure formStructure) {
        log.info("lucene更新数据:" + formStructure.getFormId());
        luceneUtil.updateIndex(formStructure);
    }

    @Override
    public void importDataToLucene(List<FormStructure> formStructureList) {
        // 刷入lucene
        luceneUtil.createIndex(formStructureList);
    }
}
